cmake_minimum_required(VERSION 3.30)
project(DataStructureAndAlgorithms)

# 设置C++标准
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 递归查找所有源代码文件
file(GLOB_RECURSE SOURCES
        "Algorithms/*.cpp"
        "DataStructure/*.cpp"
        #        "*.cpp"
)

# 为每个源文件创建独立可执行文件
foreach (source ${SOURCES})
    # 获取相对路径
    file(RELATIVE_PATH rel_path ${PROJECT_SOURCE_DIR} ${source})

    # 生成唯一目标名称（替换路径分隔符为下划线）
    string(REPLACE "/" "_" target_name ${rel_path})
    string(REPLACE ".cpp" "" target_name ${target_name})

    # 创建可执行目标
    add_executable(${target_name} ${source})
endforeach ()